package controller

import (
	"context"
	"net/http"
	"web/api"
	"web/global"
	"web/proto/myregister"

	"github.com/gin-gonic/gin"
)

//注册方法
type RegStu struct {
	Mobile   string `json:"mobile"`
	PassWord string `json:"password"`
	SmsCode  string `json:"sms_code"`
}

//注册业务
func PostRet(ctx *gin.Context) {
	var reg RegStu

	err := ctx.Bind(&reg)

	//校验数据
	if err != nil {
		global.GlobalLog.Error(context.Background(), "校验数据错误:", err)

		return
	}

	var req myregister.RegRequest
	var rsp myregister.RegResponse

	req.Mobile = reg.Mobile
	req.Password = reg.PassWord
	req.SmsCode = reg.SmsCode
	r := api.NewRegister()
	r.Register(context.Background(), &req, &rsp)
	resp := make(map[string]string)
	defer ctx.JSON(http.StatusOK, resp)

	resp["errno"] = rsp.Errno
	resp["errmsg"] = rsp.Errmsg

}
